package com.beiing.tianshuai.tianshuai.home.presenter;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.IndexSearchListBean;
import com.beiing.tianshuai.tianshuai.entity.TopSearchAndClassificationBean;
import com.beiing.tianshuai.tianshuai.home.model.ISearchModel;
import com.beiing.tianshuai.tianshuai.home.model.SearchModelImpl;
import com.beiing.tianshuai.tianshuai.home.view.ISearchView;
import com.beiing.tianshuai.tianshuai.util.LogUtils;

/**
 * Created by Jinda Yang on 2017/12/8.
 * Description :
 */

public class SearchPresenterImpl implements ISearchPresenter {

    private static final String TAG = "SearchPresenterImpl";

    private ISearchView mView;
    private ISearchModel mModel;

    public SearchPresenterImpl(ISearchView iSearchView) {
        this.mView = iSearchView;
        this.mModel = new SearchModelImpl();
    }

    @Override
    public void getTopSearchAndClassification() {
        mModel.getTopSearchAndClassification(new CallBack<TopSearchAndClassificationBean>() {
            @Override
            public void result(TopSearchAndClassificationBean bean) {
                mView.getTopSearchAndClassificationSuccess(bean);
            }

            @Override
            public void error(Throwable e) {
                mView.getTopSearchAndClassificationError(e);
            }
        });
    }

    @Override
    public void getSearchResult(final String title, int typeId) {
        mModel.getSearchResult(title, typeId, new CallBack<IndexSearchListBean>() {
            @Override
            public void result(IndexSearchListBean bean) {
                LogUtils.i(bean.toString(), TAG);
                mView.showSearchResult(bean);
            }

            @Override
            public void error(Throwable e) {
                LogUtils.i(e.toString(), TAG);
            }
        });
    }
}
